﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KCMS.BusinessLogic.Interfaces;
using StructureMap;
using KCMS.BusinessLogic.Models;

namespace KCMS.Areas.Admin.Controllers
{
    [Authorize]
    public class MenuController : Controller
    {
        //
        // GET: /Admin/Menu/
        private IMenuService menuService = ObjectFactory.GetInstance<IMenuService>();
        public ActionResult Index()
        {
            var menus = menuService.getAll();
            return View(menus);
        }
        [HttpGet]
        public ActionResult Create()
        {
            var menu = new Menu();
            return View(menu);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Create(Menu menu)
        {
            menuService.save(menu);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public ActionResult Edit(Guid id)
        {
            var model = menuService.getById(id);
            return View(model);
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(Menu menu)
        {
            //Menu old = productService.getById(menu.Id);

            //UpdateModel<Menu>(menu);
            menuService.update(menu);
            return RedirectToAction("Index");
        }
        [HttpGet]
        public ActionResult Delete()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Delete(Guid id)
        {
            menuService.delete(id);
            return RedirectToAction("Index");
        }

    }
}
